package com.fengzai.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by  峰仔  on 2017-08-03
 */
public class Zhongjie implements InvocationHandler {
    Fangdong target;

    public Object getInstance(Fangdong fangdong) {
        target = fangdong;
        //生成一个代理对象
        return Proxy.newProxyInstance(fangdong.getClass().getClassLoader(), fangdong.getClass().getInterfaces(),this);

}


    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //Object invoke = method.invoke(args);
        System.out.println(method);
        System.out.println("中介进行发布消息");
        Object invoke = method.invoke(target, args);
        System.out.println("中介进行善后工作");
        return invoke;
    }
}
